package com.zhyt.intelligentpipeline.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhyt.intelligentpipeline.mapper.CorrosionDetectionMapper;
import com.zhyt.intelligentpipeline.mapper.DeformationDetectionMapper;
import com.zhyt.intelligentpipeline.mapper.PipelineMapper;
import com.zhyt.intelligentpipeline.model.CorrosionDetection;
import com.zhyt.intelligentpipeline.model.DeformationDetection;
import com.zhyt.intelligentpipeline.model.Pipeline;
import com.zhyt.intelligentpipeline.service.PipelineService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service
public class PipelineServiceImpl extends ServiceImpl<PipelineMapper, Pipeline> implements PipelineService{

    @Resource
    private PipelineMapper pipelineMapper;



    @Override
    public List<Pipeline> getPipelines() {
        List<Pipeline> pipelines = pipelineMapper.selectList(null);
        System.out.println("管线的数量为：" + pipelines.size());
        return pipelines;
    }

    @Override
    public Pipeline getPipelineById(String id) {
        return pipelineMapper.selectById(id);
    }

    @Override
    public List<Pipeline> getPipelinesByPage(Page<Pipeline> page) {
        Page<Pipeline> pipelinePage = pipelineMapper.selectPage(page, null);
        return pipelinePage.getRecords();
    }

    @Override
    public String addPipeline(Pipeline pipeline) {
        Pipeline.checkValue(pipeline);
        String id = UUID.randomUUID().toString().replace("-","");
        pipeline.setId(id);
        pipelineMapper.insert(pipeline);
        return id;
    }

    @Override
    public Long getPipelineCounts() {
        return pipelineMapper.selectCount(null);
    }


}
